<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>

    <link rel="stylesheet" hrel="http://localhost/4.17/esri/css/main.css" />
    <script src="http://localhost/4.17/dojo/dojo.js"></script>
    <!-- 引用在线arcgis api -->
    <style>
        html,
        body,
        #viewDiv {
            height: 100%;
            width: 80%;
            margin: 0;
            padding: 0;
        }
    </style>

    <script>
        require([
            "esri/Map",
            "esri/Basemap",
            "esri/views/MapView",
            "esri/views/SceneView",
            "esri/geometry/Extent",
            "esri/geometry/SpatialReference",
            //几何
            "esri/geometry/Point",
            "esri/geometry/Polyline",
            "esri/geometry/Polygon",
            "esri/Graphic",
            "esri/widgets/Sketch",
            "esri/Color",
            //切片地图信息
            "esri/layers/support/TileInfo",
            //图层
            "esri/layers/WebTileLayer",
            "esri/views/layers/LayerView",
            "esri/layers/TileLayer",
            "esri/layers/MapImageLayer",
            "esri/layers/FeatureLayer",
            "esri/layers/GraphicsLayer",
            //符号化
            "esri/symbols/SimpleMarkerSymbol",
            "esri/symbols/SimpleFillSymbol",
            "esri/symbols/SimpleLineSymbol",
            //缓冲参数，用于GeometryService
            "esri/tasks/support/BufferParameters",
            //几何处理，投影、简化、缓冲区
            "esri/tasks/GeometryService",
            //几何引擎，用于测试、测量和分析两个或多个二维几何图形之间的空间关系,缓冲、修剪、距离、相交、联合、面积距离计算等。
            "esri/geometry/geometryEngine",
            //代理
            "esri/core/urlUtils",
            //查询
            "esri/tasks/FindTask",
            "esri/tasks/support/FindParameters",
            "esri/tasks/QueryTask",
            "esri/tasks/support/Query",
            "esri/tasks/IdentifyTask",
            "esri/tasks/support/IdentifyParameters",
            //打印地图
            "esri/tasks/PrintTask",
            "esri/tasks/support/PrintTemplate",
            "esri/tasks/support/PrintParameters",
            "dojo/dom",
            "dojo/on",
            "dojo/domReady!"
        ], function(
            Map,
            Basemap,
            MapView,
            SceneView,
            Extent,
            SpatialReference,
            Point,
            Polyline,
            Polygon,
            Graphic,
            Sketch,
            Color,
            TileInfo,
            WebTileLayer,
            LayerView,
            TileLayer,
            MapImageLayer,
            FeatureLayer,
            GraphicsLayer,
            SimpleMarkerSymbol,
            SimpleFillSymbol,
            SimpleLineSymbol,
            BufferParameters,
            GeometryService,
            geometryEngine,
            urlUtils,
            FindTask,
            FindParameters,
            QueryTask,
            Query,
            IdentifyTask,
            IdentifyParameters,
            PrintTask,
            PrintTemplate,
            PrintParameters,
            dom,
            on) {
            var startExtent = new Extent({
                xmin: 120.236368,
                ymin: 36.043567,
                xmax: 120.579018,
                ymax: 36.196569,
                spatialReference: {
                    wkid: 4549
                }
            });
            var map = new Map({ //属性：allLayers、ground、layers
                basemap: "topo",
            });
            //创建一个MapView实例（用于2D查看）并引用该地图实例
            //为了使地图在DOM中对用户可见，必须创建一个MapView并至少引用两个对象：一个Map实例和一个DOM元素。分别在map和container属性中设置。
            var view = new MapView({
                container: "viewDiv",
                map: map,
                zoom: 4,
                center: [55, 65] // longitude, latitude
            });
            var sel = true;
            $(".btnSear").click(function() {
                if (sel) {
                    $(".searDiv").fadeIn(100);
                    sel = false;
                } else {
                    sel = true;
                }
            });
            $(".searBtn").click(function() {
                queryFea();
            })

            function queryFea() {
                var sName = $(".top_search_txt").val();
                var queryTask = new QueryTask({
                    url: "http://localhost:6080/arcgis/rest/services/Qingdao1/MapServer/4"
                });
                var query = new Query();
                //query.where = "NAME='" + "%" + sName + "%" + "'";
                query.where = "Name like '%" + sName + "%'";
                //query.where = "POP04 > " + population; query.where = "NAME = '" + stateName + "'";
                query.outFields = ["*"];
                query.returnGeometry = false;
                //query.tolerance=4820;
                //query.geometry=geometry;
                queryTask.execute(query).then(function(result) {
                    console.log(result.features[0].attributes.Name);
                    if (result.features.length > 0) {
                        var tab = $("<table></table>");
                        var tr = $("<tr></tr>");
                        var th = $("<td></td>");
                        th.append("列表");
                        tr.append(th);
                        tab.append(tr);
                        var td = null;
                        for (var i = 0; i < result.features.length; i++) {
                            tr1 = $("<tr></tr>");
                            td = $("<td></td>");
                            td.append(result.features[i].attributes.Name);
                            tr1.append(td);
                            tab.append(tr1);
                        }

                        //var body = document.getElementsByTagName('body')[0];
                        // var body = document.createElement("div");
                        // body.appendChild(tab);
                        $(".resDiv").append(tab);
                        //document.body.appendChild(tab);
                    } else {
                        alert("未搜索到结果！！");
                    }
                });

                // var dmname = $(".top_search_txt").val();
                // if (dmname != null && dmname != "" && dmname != "undefined") {
                //     var queryTask = new esri.tasks.QueryTask(dmdzUrl);
                //     var query = new esri.tasks.Query();
                //     query.where = "NAME like '%" + dmname + "%'";
                //     query.returnGeometry = false;
                //     query.outFields = ["*"];
                //     queryTask.execute(query, dmxcResult);
                // }
            };
        });
    </script>
</head>

<body>
    <div style="background-color: burlywood;position:  absolute; width: 100%;height: 100%;margin: 0;padding: 0;">
        <div id="viewDiv">
        </div>
        <button class="btnSear" style="position:absolute;top:100px;right:100px;">搜索</button>

        <div class="searDiv" style="position:absolute;height:200px;width:300px;display:none;position:absolute;z-index:100;right:100px;top:200px">
            <div clasg="searchlidDiv" style="height:5Opx;width:300px;background-color:#99ff99;">
                <p style="position: absolute;left:5px;top:-4px;font-size:13px;color:ffffff">地名</p>
                <img class="closeSearDiv" style="position:absolute;right:3px;top:4px;" src="../ing/closetr5.png" />
            </div>
            <div style="height:150px;width:300px;background-color:#FFFFFF;">
                <input class="top_search_txt" style="border: 2px solid rgb(170，170, 170);position:absolute;top:40px;left:30px;" type="text" placeholder="输入关键字" /><button class="searBtn" style="background-color:#00A5FF ;border:none;position:absolute ;top:42px ;right :30px ">查询</button>
            </div>
        </div>
        <div class="resDiv" style="display: none; position:absolute;background-color: brown;top: 100px;left: 100px;width: 200px;height: 500px;">
        </div>
    </div>

</body>

</html>